package com.alibaba.springboot.health.service.impl;

import com.alibaba.springboot.health.dao.DoctorDao;
import com.alibaba.springboot.health.pojo.Doctor;
import com.alibaba.springboot.health.service.DoctorService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Doctor)表服务实现类
 *
 * @author makejava
 * @since 2019-12-28 20:25:34
 */
@Service("doctorService")
public class DoctorServiceImpl implements DoctorService {
    @Autowired
    private DoctorDao doctorDao;

    /**
     * 通过ID查询单条数据
     *
     * @param dId 主键
     * @return 实例对象
     */
    @Override
    public Doctor queryById(Integer dId) {
        return doctorDao.queryById(dId);
    }
    
    
    /**
     * 查询多条数据
     * @param page 页码
     * @param pageSize 页大小
     * @param doctor 实体
     * @return PageInfo<Doctor> 分页数据集合
     */
    @Override
    public PageInfo<Doctor> queryAll(int page, int pageSize, Doctor doctor) {
        /*拦截分页信息*/
        PageHelper.startPage(page, pageSize);

        List<Doctor> doctorList = doctorDao.queryAll(doctor);

        return new PageInfo<>(doctorList,5);
    }

    /**
     * 新增数据
     *
     * @param doctor 实例对象
     * @return 实例对象
     */
    @Override
    public Doctor insert(Doctor doctor) {
        doctorDao.insert(doctor);
        return doctor;
    }

    /**
     * 修改数据
     *
     * @param doctor 实例对象
     * @return 实例对象
     */
    @Override
    public Doctor update(Doctor doctor) {
        doctorDao.update(doctor);
        return queryById(doctor.getDId());
    }

    /**
     * 通过主键删除数据
     *
     * @param dId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer dId) {
        return doctorDao.deleteById(dId) > 0;
    }

    /**
     * jrl
     * @return
     */
    @Override
    public List<Doctor> selectAllDoctor() {
        return doctorDao.selectAllDoctor();
    }
}